package com.aiden.cashbook.data.user

import com.aiden.cashbook.bean.User
import com.aiden.cashbook.dao.UserDao
import com.aiden.cashbook.data.Callback
import com.aiden.cashbook.db.DaoHelper

class UserLocalDataSource: UserDataSource {
    override fun getCode(phone: String, type: String, callback: Callback<String>) {
        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    }

    override fun auth(phone: String, code: String, type: String, callback: Callback<User>) {
        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    }

    override fun modify(user: User, callback: Callback<User>) {
        TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
    }

    override fun userInfo(id: Long, callback: Callback<User>) {
        try {
            val user = DaoHelper.getUserDao().queryBuilder().where(UserDao.Properties.Id.eq(id)).build().unique()
            callback.onSuccess(user)
        } catch (e: Exception) {
            e.printStackTrace()
            callback.onFailure("数据库加载失败")
        }
    }
}